import request from '@/utils/request'

/**
 * 我的代理商初始化
 */
export function init() {
  return request({
    url: '/agent/agent/my_agent',
    methods: 'GET'
  })
}

/**
 * 我的代理商查询
 * @param {Number} date 查询参数
 */
export function search(date) {
  const data = {
    agent_name: date.agent_name,
    telphone: date.phone,
    agent_num: date.sn,
    status: date.agent_status
  }
  return request({
    url: '/agent/agent/my_agent',
    method: 'GET',
    params: data
  })
}

/**
 * 代理商停用开启
 * @param {Number} id 编号
 * @param {Number} state 状态 0 => 开启 1 => 停用
 */
export function state(agent_num, status) {
  const data = {
    agent_num,
    status
  }
  return request({
    url: '/agent/agent/stop_agent',
    method: 'POST',
    data
  })
}

/**
 * 添加代理商
 * @param {Object} date 参数
 * @param {Object} official 参数
 * @param {Object} wsChannel 参数
 * @param {Object} fuChannel 参数
 * @param {Object} leChannel 参数
 * @param {Object} xdlChannel 参数
 */
export function addAgent(date, official, wsChannel, fuChannel, leChannel, xdlChannel) {
  // 地区数组 转换
  const data = {
    name: date.username,
    password: date.password,
    telphone: date.telphone,
    start_time: date.time ? date.time[0] : '',
    expire_time: date.time ? date.time[1] : '',
    agent_name: date.agent_name,
    respo_name: date.respo_name,
    is_sub: date.is_sub ? 1 : 0,
    is_market: date.is_market ? 1 : 0,
    agent_region: date.area_address,
    rates: {
      wx: {
        normal: official.p_wx_rate,
        green: official.l_wx_rate,
        charity: official.g_wx_rate
      },
      ali: {
        normal: official.p_ali_rate,
        blue: official.l_ali_rate,
        charity: official.g_ali_rate
      },
      ws: {
        wx: {
          normal: wsChannel.p_wx_rate
        },
        ali: {
          normal: wsChannel.p_ali_rate,
          blue: wsChannel.l_ali_rate
        }
      },
      fumin: {
        wx: {
          normal: fuChannel.p_wx_rate,
          green: fuChannel.l_wx_rate
        },
        ali: {
          normal: fuChannel.p_ali_rate,
          blue: fuChannel.l_ali_rate
        }
      },
      lepos_swipe: {
        debit: {
          d1: {
            rate: leChannel.pos_d1_j_rate,
            ceiling: leChannel.pos_d1_j_f
          },
          d0: {
            rate: leChannel.pos_d0_j_rate
          }
        },
        credit: {
          d1: {
            rate: leChannel.pos_d1_d_rate
          },
          d0: {
            rate: leChannel.pos_d0_d_rate
          }
        },
        ovsea: {
          d1: {
            rate: leChannel.pos_d1_w_rate
          },
          d0: {
            rate: leChannel.pos_d0_w_rate
          }
        }
      },
      lepos_unipay: {
        debit: {
          d1: {
            greater: {
              rate: leChannel.yl_d1_j_b1000_rate,
              ceiling: leChannel.yl_d1_j_b1000_f
            },
            less: {
              rate: leChannel.yl_d1_j_s1000_rate
            }
          },
          d0: {
            greater: {
              rate: leChannel.yl_d0_j_b1000_rate
            },
            less: {
              rate: leChannel.yl_d0_j_s1000_rate
            }
          }
        },
        credit: {
          d1: {
            less: {
              rate: leChannel.yl_d1_d_s1000_rate
            },
            greater: {
              rate: leChannel.yl_d1_d_b1000_rate
            }
          },
          d0: {
            less: {
              rate: leChannel.yl_d0_d_s1000_rate
            },
            greater: {
              rate: leChannel.yl_d0_d_b1000_rate
            }
          }
        }
      },
      lepos_mob: {
        d1: {
          rate: leChannel.s_d1_rate
        },
        d0: {
          rate: leChannel.s_d0_rate
        }
      },
      starpos_swipe: {
        debit: {
          t1: {
            ceiling: xdlChannel.pos_t1_j_b1000_f,
            rate: xdlChannel.pos_t1_j_b1000_rate
          }
        },
        credit: {
          t1: {
            rate: xdlChannel.pos_t1_d_rate
          }
        }
      },
      starpos_unipay: {
        debit: {
          t1: {
            less: {
              rate: xdlChannel.yl_t1_j_s1000_rate
            },
            greater: {
              rate: xdlChannel.yl_t1_j_b1000_rate,
              ceiling: xdlChannel.yl_t1_j_b1000_f
            }
          }
        },
        credit: {
          t1: {
            less: {
              rate: xdlChannel.yl_t1_d_s1000_rate
            },
            greater: {
              rate: xdlChannel.yl_t1_d_b1000_rate
            }
          }
        }
      },
      starpos_mob: {
        t1: {
          rate: xdlChannel.s_t1_rate
        }
      }
    }
  }

  return request({
    url: '/agent/agent/add',
    method: 'POST',
    data
  })
}

/**
 * 修改代理商
 * @param {Object} date 参数
 * @param {Object} official 参数
 * @param {Object} wsChannel 参数
 * @param {Object} fuChannel 参数
 * @param {Object} leChannel 参数
 * @param {Object} xdlChannel 参数
 */
export function editAgent(date, official, wsChannel, fuChannel, leChannel, xdlChannel) {
  // 地区数组 转换
  const data = {
    name: date.username,
    password: date.password,
    telphone: date.telphone,
    start_time: date.time ? date.time[0] : '',
    expire_time: date.time ? date.time[1] : '',
    agent_name: date.agent_name,
    agent_num: date.agent_num,
    respo_name: date.respo_name,
    is_sub: date.is_sub ? 1 : 0,
    is_market: date.is_market ? 1 : 0,
    agent_region: date.area_address,
    rates: {
      wx: {
        normal: official.p_wx_rate,
        green: official.l_wx_rate,
        charity: official.g_wx_rate
      },
      ali: {
        normal: official.p_ali_rate,
        blue: official.l_ali_rate,
        charity: official.g_ali_rate
      },
      ws: {
        wx: {
          normal: wsChannel.p_wx_rate
        },
        ali: {
          normal: wsChannel.p_ali_rate,
          blue: wsChannel.l_ali_rate
        }
      },
      fumin: {
        wx: {
          normal: fuChannel.p_wx_rate,
          green: fuChannel.l_wx_rate
        },
        ali: {
          normal: fuChannel.p_ali_rate,
          blue: fuChannel.l_ali_rate
        }
      },
      lepos_swipe: {
        debit: {
          d1: {
            rate: leChannel.pos_d1_j_rate,
            ceiling: leChannel.pos_d1_j_f
          },
          d0: {
            rate: leChannel.pos_d0_j_rate
          }
        },
        credit: {
          d1: {
            rate: leChannel.pos_d1_d_rate
          },
          d0: {
            rate: leChannel.pos_d0_d_rate
          }
        },
        ovsea: {
          d1: {
            rate: leChannel.pos_d1_w_rate
          },
          d0: {
            rate: leChannel.pos_d0_w_rate
          }
        }
      },
      lepos_unipay: {
        debit: {
          d1: {
            greater: {
              rate: leChannel.yl_d1_j_b1000_rate,
              ceiling: leChannel.yl_d1_j_b1000_f
            },
            less: {
              rate: leChannel.yl_d1_j_s1000_rate
            }
          },
          d0: {
            greater: {
              rate: leChannel.yl_d0_j_b1000_rate
            },
            less: {
              rate: leChannel.yl_d0_j_s1000_rate
            }
          }
        },
        credit: {
          d1: {
            less: {
              rate: leChannel.yl_d1_d_s1000_rate
            },
            greater: {
              rate: leChannel.yl_d1_d_b1000_rate
            }
          },
          d0: {
            less: {
              rate: leChannel.yl_d0_d_s1000_rate
            },
            greater: {
              rate: leChannel.yl_d0_d_b1000_rate
            }
          }
        }
      },
      lepos_mob: {
        d1: {
          rate: leChannel.s_d1_rate
        },
        d0: {
          rate: leChannel.s_d0_rate
        }
      },
      starpos_swipe: {
        debit: {
          t1: {
            ceiling: xdlChannel.pos_t1_j_b1000_f,
            rate: xdlChannel.pos_t1_j_b1000_rate
          }
        },
        credit: {
          t1: {
            rate: xdlChannel.pos_t1_d_rate
          }
        }
      },
      starpos_unipay: {
        debit: {
          t1: {
            less: {
              rate: xdlChannel.yl_t1_j_s1000_rate
            },
            greater: {
              rate: xdlChannel.yl_t1_j_b1000_rate,
              ceiling: xdlChannel.yl_t1_j_b1000_f
            }
          }
        },
        credit: {
          t1: {
            less: {
              rate: xdlChannel.yl_t1_d_s1000_rate
            },
            greater: {
              rate: xdlChannel.yl_t1_d_b1000_rate
            }
          }
        }
      },
      starpos_mob: {
        t1: {
          rate: xdlChannel.s_t1_rate
        }
      }
    }
  }

  return request({
    url: '/agent/agent/edit',
    method: 'POST',
    data
  })
}

/**
 * 修改代理商查看
 */
export function editAgentInit(agent_num) {
  return request({
    url: '/agent/agent/query_info',
    method: 'GET',
    params: { agent_num }
  })
}

/**
 * 查看我的结算价
 * @param {String} channel_type 通道类型
 */
export function GetMySettlePrice(channel_type) {
  return request({
    url: '/agent/agent/get_my_settle_price',
    method: 'GET',
    params: { channel_type }
  })
}

/**
 * 添加获取上级代理商信息
 */
export function GetCurrentAgentInfo() {
  return request({
    url: '/agent/agent/current_agent_info',
    method: 'GET'
  })
}

/**
 * 我的代理商分页
 * @param {Number} page 页码
 * @param {Object} date 参数
 */
export function page(page, date) {
  const data = {
    page,
    agent_name: date.agent_name,
    telphone: date.phone,
    agent_num: date.sn,
    status: date.agent_status
  }

  return request({
    url: '/agent/agent/my_agent',
    method: 'GET',
    params: data
  })
}

export function validUserName(name) {
  return request({
    url: '/is_user',
    method: 'GET',
    params: { name }
  })
}

/**
 * 是否允许发展下级代理商
 */
export function myAgentIsSub() {
  return request({
    url: '/agent/agent/is_sub',
    method: 'GET'
  })
}

/**
 * 下级代理商初始化
 * @param {Number} id 代理商id
 */
export function SubAgentInit(id) {
  return request({
    url: '/agent/agent/sub',
    method: 'get',
    params: { id }
  })
}

/**
 * 下级代理商查询
 * @param {Object} query 查询参数
 */
export function agentSubSearch(query) {
  return request({
    url: '/agent/agent/sub',
    method: 'get',
    params: query
  })
}

/**
 * 下级代理商分页
 * @param {Number} id 代理商id
 * @param {Number} page 页码
 * @param {Object} date 查询参数
 */
export function nextAgentPage(id, page, date) {
  return request({
    url: '/agent/agent/sub',
    method: 'GET',
    params: { id, page, agent_name: date.agent_name, sn: date.sn, status: date.status }
  })
}

/**
 * 空码预制
 * @param {Object} date 空码预制参数
 */
export function addDayNum(date) {
  const data = { agent_num: date.agent_num, num: date.num }
  return request({
    url: '/agent/agent/add_imit',
    method: 'POST',
    data
  })
}

/**
 * 获取批次列表
 */
export function getBatchList() {
  return request({
    url: '/agent/busin_code/get_batch_list',
    method: 'GET'
  })
}

/**
 * 获取批次列表分页
 */
export function getBatchListPage(page) {
  return request({
    url: '/agent/busin_code/get_batch_list',
    method: 'GET',
    params: { page }
  })
}

/**
 * 新增二维码
 */
export function qrCodeAddPost(date) {
  const data = {
    quantity: date.num,
    style: date.softwares,
    logo: date.style
  }
  return request({
    url: '/agent/busin_code/make_codes',
    method: 'POST',
    data
  })
}

/**
 * 批量导出二维码
 */
export function exprotQrcode(code) {
  const data = { code }
  return request({
    url: '/agent/busin_code/export_multi',
    method: 'POST',
    data
  })
}

/**
 * 导出单个二维码
 */
export function exprotQrcodeOne(code) {
  return request({
    url: '/agent/busin_code/export_one',
    method: 'GET',
    params: { code }
  })
}

/**
 * 获取展业码列表
 */
export function getCodeList(date) {
  return request({
    url: '/agent/busin_code/get_code_list',
    method: 'GET',
    params: { agent_num: date.agent_num, batch_num: date.batch_num }
  })
}

/**
 * 搜索展业码列表
 */
export function searchCodeList(date, list) {
  return request({
    url: '/agent/busin_code/get_code_list',
    method: 'GET',
    params: { mch_name: date.mch_name, code: date.code, mch_num: date.merchant_num, batch_num: list.batch_num, agent_num: list.agent_num }
  })
}

/**
 * 全部导出
 */
export function downloadFileAll(agent_num, batch_num) {
  return request({
    url: '/agent/busin_code/get_code_all',
    method: 'GET',
    params: { agent_num, batch_num }
  })
}

/**
 * 获取展业码列表分页
 */
export function getCodeListCurrent(date, page) {
  return request({
    url: '/agent/busin_code/get_code_list',
    method: 'GET',
    params: { agent_num: date.agent_num, batch_num: date.batch_num, page }
  })
}

/**
 * 解绑展业码
 */
export function postUnbindCode(code) {
  return request({
    url: '/agent/busin_code/untie',
    method: 'POST',
    params: { code }
  })
}

/**
 * 代理商审核初始化
 */
export function validAgentInit() {
  return request({
    url: '/agent/agent/check_list',
    method: 'GET'
  })
}

/**
 * 获取代理商列表
 */
export function GetAgentList() {
  return request({
    url: '/agent/agent/my_agent_list',
    method: 'GET'
  })
}

/**
 * 获取代理商状态
 */
export function GetAgentStatus() {
  return request({
    url: '/agent/agent/agent_status',
    method: 'GET'
  })
}

/**
 * 代理商审核条数获取
 */
export function GetValidGread() {
  return request({
    url: '/agent/agent/check_num',
    method: 'GET'
  })
}

/**
 * 代理商审核搜索
 * @param {Object} date 搜索条件
 */
export function validAgentSearch(date) {
  return request({
    url: '/agent/agent/check_list',
    method: 'GET',
    params: { agent_num: date.agent_num, agent_name: date.agent_name, telphone: date.phone }
  })
}

/**
 * 代理商审核分页
 * @param {Object} date 搜索条件
 */
export function validAgentPage(date, page) {
  return request({
    url: '/agent/agent/check_list',
    method: 'GET',
    params: { agent_num: date.agent_num, agent_name: date.agent_name, telphone: date.phone, page }
  })
}

/**
 * 获取待审核代理商名称列表
 */
export function validAgentName() {
  return request({
    url: '/agent/agent/check_agent_list',
    method: 'GET'
  })
}

/**
 * 审核查看代理商资料
 * @param {Number} agent_num 代理商编号
 */
export function validAgentList(agent_num) {
  return request({
    url: '/agent/agent/query_check_info',
    method: 'GET',
    params: { agent_num }
  })
}

/**
 * 审核操作
 * @param {Nunber} agent_num 代理商编号
 * @param {Number} status 操作标示
 */
export function validAgentSubmit(agent_num, status, error_info) {
  return request({
    url: '/agent/agent/check_status',
    method: 'PUT',
    params: { agent_num, status, error_info }
  })
}

